<?php

/**
 * Teacher
 * @property	int		$id
 * @property    string  $teacherNo
 * @property	string	$name
 * @property	string	$collegeId
 * @property    string  $sex
 * @property    string  $hireTime
 * @property	string	$created
 * @property	string	$updated
 */
class Teacher extends Node
{
    public static function option() {
        return array(
            'table' => 'Teacher',
            'key' => 'id',
            'columns' => array(
                'id' => 'id',
                'teacherNo' => 'teacher_no',
                'name' => 'name',
                'collegeId' => 'college_id',
                'sex' => 'sex',
                'hireTime' => 'hire_time',
                'created' => 'created',
                'updated' => 'updated',
                'attributeData' => 'attributes',
            ));
    }
    public static function attributesList() {
        return [
            'id',
            'teacherNo',
            'name',
            'collegeId',
            'sex',
            'hireTime',
        ];
    }
    /**
     * @return College
     */
    public function college() {
        return College::load($this->collegeId);
    }
    /**
     * @return User
     */
    public function user() {
        return array_values(User::find(new Query('internalId', $this->id)))[0];
    }

    public function remove() {
        $courseClasses = CourseClass::find(new Query('teacherId', $this->id), ['nolimit' => 1]);
        foreach ($courseClasses as $courseClass) $courseClass->remove();
        $users = User::find(new Query('internalId', $this->id), ['nolimit' => 1]);
        foreach ($users as $user) $user->delete();
        $this->delete();
    }
}